
import mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import pojo.User;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class Mybastis03 {
    public static void main(String[] args) throws IOException {
//        操作Mybastis的四个步骤
//        1.加载配置文件

        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
//        2.创建SqlSe
        SqlSession sqlSession = sqlSessionFactory.openSession();
//        3.执行sql
//        List<User> users = sqlSession.selectList("test.selectAll");
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        User oneUser = userMapper.seleectOne(1);
        System.out.println(oneUser);
//        4.关闭Sess
        sqlSession.close();
    }
}
